<template>
  <view class="balance-page">
    
    <!-- 余额卡片 -->
    <view class="balance-card">
      <view class="balance-title">账户余额(元)</view>
      <view class="balance-amount">{{balance}}</view>
    </view>
    
    <!-- 操作按钮 -->
    <view class="action-buttons">
      <button class="btn recharge" @click="handleRecharge">充值</button>
    </view>
    
    <!-- 交易记录 -->
    <view class="record-section">
      <view class="section-header">
        <text class="section-title">交易记录</text>
        <!-- <text class="see-all" @click="viewAllRecords">查看全部</text> -->
      </view>
      
      <view class="record-list">
        <view class="record-item" v-for="(item, index) in records" :key="index" @click="viewRecordDetail(item)">
          <view class="record-left">
            <view class="record-type">{{item.type}}</view>
            <view class="record-time">{{item.time}}</view>
          </view>
          <view class="record-amount" :class="{ 'income': item.amount > 0, 'expense': item.amount < 0 }">
            {{item.amount > 0 ? '+' : ''}}{{item.amount}}
          </view>
        </view>
        
        <view class="no-records" v-if="records.length === 0">
          暂无交易记录
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      balance: 1258.50,
      records: [
        {
          id: 1,
          type: '商品消费',
          time: '2023-05-15 14:30',
          amount: -128.00,
          status: '已完成'
        },
        {
          id: 2,
          type: '充值',
          time: '2023-05-10 09:15',
          amount: +500.00,
          status: '已完成'
        },
        {
          id: 3,
          type: '退款',
          time: '2023-05-08 16:45',
          amount: +68.00,
          status: '已完成'
        }
      ]
    }
  },
  methods: {
    handleRecharge() {
      uni.showToast({
        title: '跳转充值页面',
        icon: 'none'
      });
      // 实际开发中可以跳转到充值页面
      // uni.navigateTo({
      //   url: '/pages/recharge/recharge'
      // });
    },
    handleWithdraw() {
      uni.showToast({
        title: '跳转提现页面',
        icon: 'none'
      });
      // 实际开发中可以跳转到提现页面
      // uni.navigateTo({
      //   url: '/pages/withdraw/withdraw'
      // });
    },
    viewAllRecords() {
      uni.showToast({
        title: '查看全部记录',
        icon: 'none'
      });
      // 实际开发中可以跳转到记录列表页面
      // uni.navigateTo({
      //   url: '/pages/records/records'
      // });
    },
    viewRecordDetail(item) {
      uni.showToast({
        title: `查看记录详情: ${item.id}`,
        icon: 'none'
      });
      // 实际开发中可以跳转到详情页面
      // uni.navigateTo({
      //   url: `/pages/recordDetail/recordDetail?id=${item.id}`
      // });
    }
  }
}
</script>

<style lang="scss" scoped>
.balance-page {
  padding: 20rpx;
  background-color: #f7f7f7;
  min-height: 100vh;
  box-sizing: border-box;
}

.nav-bar {
  height: 88rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  
  .nav-title {
    font-size: 36rpx;
    font-weight: bold;
    color: #333;
  }
}

.balance-card {
  background: linear-gradient(135deg, #4a6cf7, #6a11cb);
  border-radius: 20rpx;
  padding: 40rpx;
  color: #fff;
  margin: 20rpx 0;
  box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.1);
  
  .balance-title {
    font-size: 28rpx;
    opacity: 0.9;
  }
  
  .balance-amount {
    font-size: 72rpx;
    font-weight: bold;
    margin: 20rpx 0;
  }
  
  .balance-tips {
    font-size: 24rpx;
    opacity: 0.8;
  }
}

.action-buttons {
  display: flex;
  justify-content: space-between;
  margin: 40rpx 0;
  
  .btn {
    flex: 1;
    height: 80rpx;
    line-height: 80rpx;
    border-radius: 40rpx;
    font-size: 32rpx;
    color: #fff;
    border: none;
    
    &.recharge {
      background-color: #4a6cf7;
      margin-right: 20rpx;
    }
    
    &.withdraw {
      background-color: #ff6b6b;
      margin-left: 20rpx;
    }
  }
}

.record-section {
  background-color: #fff;
  border-radius: 20rpx;
  padding: 30rpx;
  box-shadow: 0 5rpx 15rpx rgba(0, 0, 0, 0.05);
  
  .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30rpx;
    
    .section-title {
      font-size: 32rpx;
      font-weight: bold;
      color: #333;
    }
    
    .see-all {
      font-size: 26rpx;
      color: #999;
    }
  }
}

.record-list {
  .record-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 25rpx 0;
    border-bottom: 1rpx solid #f0f0f0;
    
    &:last-child {
      border-bottom: none;
    }
    
    .record-left {
      flex: 1;
    }
    
    .record-type {
      font-size: 30rpx;
      color: #333;
      margin-bottom: 10rpx;
    }
    
    .record-time {
      font-size: 24rpx;
      color: #999;
    }
    
    .record-amount {
      font-size: 32rpx;
      font-weight: bold;
      
      &.income {
        color: #4a6cf7;
      }
      
      &.expense {
        color: #ff6b6b;
      }
    }
  }
  
  .no-records {
    text-align: center;
    padding: 50rpx 0;
    color: #999;
    font-size: 28rpx;
  }
}
</style>